#ifndef VECTOR3D_H
#define VECTOR3D_H

#include "math.h"
#include <QDebug>
#include <QObject>

/** 王诗阳三维向量对象 WSY 20201207 */
class Vector3D : public QObject
{
    Q_OBJECT
public:
    Vector3D(double deltaX, double deltaY, double deltaZ) {
        this->setValues(deltaX, deltaY, deltaZ);
    }
    ~Vector3D() {

    }
    //当前向量的长度
    virtual double length()
    {
        return sqrt(pow(this->deltaX, 2) + pow(this->deltaY, 2) + pow(this->deltaZ, 2));
    }
    //将向量标准化
    virtual Vector3D *normalize()
    {
        //Vector3D vectorA;
        double length = this->length();
        Vector3D *vectorA = new Vector3D(
                    this->deltaX / length, this->deltaY / length, this->deltaZ / length);
        return vectorA;
    }
    virtual Vector3D *addNewVector(Vector3D *vector) {
        return new Vector3D(this->deltaX + vector->getDeltaX(),
                            this->deltaY + vector->getDeltaY(),
                            this->deltaZ + vector->getDeltaZ());
    }
    Vector3D *multiply(double length)
    {
        return new Vector3D(
                    this->deltaX * length, this->deltaY * length, this->deltaZ * length);
    }
    virtual void printSingleDirection()
    {
        qDebug() << "deltaX: " << this->deltaX << " deltaY: " << this->deltaY <<
                    " deltaZ: " << this->deltaZ << " length: " << this->length();
    }
    void setValues(double deltaX, double deltaY, double deltaZ)
    {
        this->deltaX = deltaX; this->deltaY = deltaY; this->deltaZ = deltaZ;
    }
    virtual double getDeltaX() { return deltaX; }
    virtual double getDeltaY() { return deltaY; }
    virtual double getDeltaZ() { return deltaZ; }

private:
    double deltaX, deltaY, deltaZ;
};

#endif // VECTOR3D_H
